package com.feicheng.persistence.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.ARoom;
import com.feicheng.persistence.mapper.ARoomMapper;
import com.feicheng.persistence.model.RoomStoreModel;
import com.feicheng.persistence.service.IARoomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cailongyang
 * @since 2025-02-11
 */
@Service
public class ARoomServiceImpl extends ServiceImpl<ARoomMapper, ARoom> implements IARoomService {

    @Autowired
    ARoomMapper aroomMapper;



    //分页查询房间信息
    public ResultInfo getRoomByPage(Integer current, Integer size, JSONObject param){
        String roomname = param.getObject("roomname",String.class);
        //初始化mybatis-plus提供的page对象
        Page<RoomStoreModel> pages = new Page<>(current, size);
        //初始化mybatis-plus提供的queryWrapper对象
        QueryWrapper<RoomStoreModel> queryWrapper = new QueryWrapper<RoomStoreModel>();
        //设置查询条件
        queryWrapper.like("roomname",roomname);
        return ResultInfo.success(aroomMapper.getRoomPage(pages,queryWrapper));
    }


    //新增房间信息
    public ResultInfo newRoom(JSONObject param) {
        ARoom room = param.getObject("room", ARoom.class);
        save(room);//避免循环依赖，直接调用类中的save方法
        System.out.println(room);
        return ResultInfo.success("房间新增成功！");
    }

    //删除房间信息
    public ResultInfo deleteRoom(String roomid) {
        //初始化mybatis-plus提供的queryWrapper对象
        QueryWrapper<ARoom> qw = new QueryWrapper<ARoom>();
        qw.eq("roomid", roomid);

        remove(qw);//避免循环依赖，直接调用类中的remove方法
        return ResultInfo.success();
    }
}
